var cols = 16;
var rows = 24;
var cellMargin = "2px";
var cellSize = "12px";
var cellBorderSize = "1px";

var cellColor = "#FF0000";
var cellBorderColor = "#000000";
var cellBorderType = "solid";

var defaultCellColor = "#FFFFFF";
var defaultCellBorderColor = "#000000";
var defaultCellBorderType = "solid";

var panelColor = "#EEEEEE";
var panelBorderSize = "1px";
var panelBorderColor = "#000000";
var panelBorderType = "solid";
var showTblState = 'off';
var mouseState = 0;

function setRowNum(rowNum) {
	$('squarePlace').load('makeSquare@squarePlace.jsp');
	rows = rowNum;
	var URL = "./makeSquare@squarePlace.jsp?";
	URL = URL + "cols=" + cols + "&rows=" + rows;
	parent.document.getElementById('squarePlace').location.href = URL;
	document.parent.getElementById('squarePlace').location.reload();
	// parent.innerShowFrame.href = URL;
}

function _setRowNum(rowNum) {
	rows = rowNum;
	var URL = "./makeSquare@squarePlace.jsp?";
	URL = URL + "cols=" + cols + "&rows=" + rows;
	parent.innerShowFrame.href = URL;
}

function setColNum(colNum) {
	cols = colNum;
	var URL = "./makeSquare@squarePlace.jsp?";
	URL = URL + "cols=" + cols + "&rows=" + rows;
	parent.innerShowFrame.location.href = URL;
}

/* ******************************************************** cell */
function setCellColor(color) {
	cellColor = "#" + color;
	modify_style('.cellChange', 'backgroundColor', cellColor);
	modify_style2('.cellChange', 'backgroundColor', cellColor);
}

function setCellBorderColor(color) {
	cellBorderColor = "#" + color;
	var borderStyle = cellBorderSize + " " + cellBorderColor + " "
			+ cellBorderType;
	modify_style('.cellChange', 'border', borderStyle);
	modify_style2('.cellChange', 'border', borderStyle);
}

function setDefaultCellColor(color) {
	cellColor = "#" + color;
	modify_style('.cellSquare', 'backgroundColor', cellColor);
	modify_style2('.cellSquare', 'backgroundColor', cellColor);
}

function setDefaultCellBorderColor(color) {
	defaultCellBorderColor = "#" + color;
	var borderStyle = cellBorderSize + " " + defaultCellBorderColor + " "
			+ cellBorderType;
	modify_style('.cellSquare', 'border', borderStyle);
	modify_style2('.cellSquare', 'border', borderStyle);
}

function setCellSize(size) {
	cellSize = size + "px";
	modify_style('.cellSquare', 'width', cellSize);
	modify_style('.cellSquare', 'height', cellSize);
	modify_style('.cellChange', 'width', cellSize);
	modify_style('.cellChange', 'height', cellSize);

	modify_style2('.cellSquare', 'width', cellSize);
	modify_style2('.cellSquare', 'height', cellSize);
	modify_style2('.cellChange', 'width', cellSize);
	modify_style2('.cellChange', 'height', cellSize);
}

function setCellBorderSize(size) {
	cellBorderSize = size;
	var borderStyle = cellBorderSize + " " + cellBorderColor + " "
			+ cellBorderType;
	modify_style('.cellSquare', 'border', borderStyle);
	modify_style('.cellChange', 'border', borderStyle);

	modify_style2('.cellSquare', 'border', borderStyle);
	modify_style2('.cellChange', 'border', borderStyle);
}

function setCellBorderType(type) {
	cellBorderType = type;
	var borderStyle = cellBorderSize + " " + cellBorderColor + " "
			+ cellBorderType;
	modify_style('.cellChange', 'border', borderStyle);
	modify_style2('.cellChange', 'border', borderStyle);
}

function setDefaultCellBorderType(type) {
	defaultCellBorderType = type;
	var borderStyle = cellBorderSize + " " + cellBorderColor + " "
			+ defaultCellBorderType;
	modify_style('.cellSquare', 'border', borderStyle);
	modify_style2('.cellSquare', 'border', borderStyle);
}
/* ******************************************************** panel */

function setPanelColor(color) {
	panelColor = "#" + color;
	modify_style('#place', 'backgroundColor', panelColor);
	modify_style2('#place', 'backgroundColor', panelColor);
}

function setPanelBorderSize(size) {
	panelBorderSize = size;
	var borderStyle = panelBorderSize + " " + panelBorderColor + " "
			+ panelBorderType;
	modify_style('#place', 'border', borderStyle);
	modify_style2('#place', 'border', borderStyle);
}

function setPanelBorderColor(color) {
	panelBorderColor = "#" + color;
	var borderStyle = panelBorderSize + " " + panelBorderColor + " "
			+ panelBorderType;
	modify_style('#place', 'border', borderStyle);

	modify_style2('#place', 'border', borderStyle);
}

function setPanelBorderType(type) {
	panelBorderType = type;
	var borderStyle = panelBorderSize + " " + panelBorderColor + " "
			+ panelBorderType;
	modify_style('#place', 'border', borderStyle);

	modify_style2('#place', 'border', borderStyle);
}

function loadStyle() {
}

function mouseDown() {
	mouseState = 1;
}

function mouseOver() {
	mouseState = 2;
}

function mousePaint() {
	if (mouseState == 1) {
		this.className = 'cellChange()';
	}
}

function checkNum(id, num) {
	var value = document.getElementById(id).value;
	if (value > num) {
		alert(num + "���� Ů�ϴ�.");
		document.getElementById(id).value = num;
	}
}

function inputEnter(pcNum, prNum) {
	if (window.event.keyCode == 13) {
		setSession(pcNum, pcNum);
		setTimeout('setSession(prNum,prNum)', 100);
		setTimeout('F5()', 100);
	}
}

function setCellNum(col, row) {
	var col = document.getElementById(col).value;
	var row = document.getElementById(row).value;
	var url = "squareLv1.jsp?col=" + col + "&row=" + row;
	top.location.href = url;
}

function setSession(p, v) {
	var val = document.getElementById(v).value;
	var url = "setSession.jsp?sParam=" + p + "&sValue=" + val;
	top.frameSession.location.href = url;
}

function F5() {
	top.location.reload();
}

function changeStyle() {
	alert("change");
	if (!document.styleSheets) {
		return;
	}
	alert("1");
	var theRules = new Array();
	if (document.styleSheets[0].cssRules) {
		theRules = document.styleSheets[0].cssRules
	} else if (document.styleSheets[0].rules) {
		theRules = document.styleSheets[0].rules
	} else {
		return;
	}
	alert("2");
	theRules[theRules.length - 1].style.backgroundColor = "#FFFFFF";
}

function modify_style(selector, property, value) {
	var styleSheet = document.styleSheets;
	var changed = false;

	if (!styleSheet.length) {
		var newStyle = document.createElement("style");
		newStyle.type = "text/css";
		document.getElementsByTagName("head")[0].appendChild(newStyle);
	}
	if (!property)
		property = "cssText";
	for (var i = 0, style_len = styleSheet.length; i < style_len; i++) {
		var rule = styleSheet[i].cssRules ? styleSheet[i].cssRules
				: styleSheet[i].rules;
		for (var j = 0, rule_len = rule.length; j < rule_len; j++) {
			if (rule[j].selectorText.toLowerCase() == selector.toLowerCase()) {
				rule[j].style[property] = value;
				changed = true;
			}
		}
	}
	if (!changed) {
		var style = document.styleSheets[0];
		if (property == "cssText")
			var cssText = value;
		else
			var cssText = property + ":" + value;

		if (style.insertRule)
			style.insertRule(selector + "{" + cssText + "}",
					style.cssRules.length);
		else if (style.addRule)
			style.addRule(selector, cssText);
		else
			return false;
	}
}

function modify_style2(selector, property, value) {
	var styleSheet = innerShowFrame.document.styleSheets;
	var changed = false;

	if (!styleSheet.length) {
		var newStyle = document.createElement("style");
		newStyle.type = "text/css";
		document.getElementsByTagName("head")[0].appendChild(newStyle);
	}
	if (!property)
		property = "cssText";
	for (var i = 0, style_len = styleSheet.length; i < style_len; i++) {
		var rule = styleSheet[i].cssRules ? styleSheet[i].cssRules
				: styleSheet[i].rules;
		for (var j = 0, rule_len = rule.length; j < rule_len; j++) {
			if (rule[j].selectorText.toLowerCase() == selector.toLowerCase()) {
				rule[j].style[property] = value;
				changed = true;
			}
		}
	}
	if (!changed) {
		var style = document.styleSheets[0];
		if (property == "cssText")
			var cssText = value;
		else
			var cssText = property + ":" + value;

		if (style.insertRule)
			style.insertRule(selector + "{" + cssText + "}",
					style.cssRules.length);
		else if (style.addRule)
			style.addRule(selector, cssText);
		else
			return false;
	}
}

function showTbl(tbl) {
	if (showTblState == 'off') {
		document.getElementById(tbl).style.display = "block";
		showTblState = tbl;
	} else {
		if (showTblState == tbl) {
			document.getElementById(showTblState).style.display = "none";
			showTblState = 'off';
		} else {
			document.getElementById(showTblState).style.display = "none";
			document.getElementById(tbl).style.display = "block";
			showTblState = tbl;
		}
	}
}

function viewSize(size) {
	document.getElementById("cellSizeValue").value = size + "px";
}
// document.onkeydown= inputEnter;



window.onload = function() {

}